﻿using Communication;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsFormsApp1.Utils;

namespace Jn698._45GWTool.ViewModels.Controls
{
    public class CrcCheckViewModel:ViewModelBase
    {
		private string frameData;

		public string FrameData
		{
			get { return frameData; }
			set { frameData = value;RaisePropertyChanged(); }
		}

		private string crc;

		public string CRC
		{
			get { return crc; }
			set { crc = value; RaisePropertyChanged(); }
		}
		 
		public RelayCommand CrcCheckCommand
		{
			get
			{
				return new RelayCommand(() =>
				{
					try
					{
                        var check = CheckSum.CRC16(StringUtils.hexStringToBytes(FrameData.Replace(" ", "")), 0);
                        CRC = check[0].ToString("X2") + " " + check[1].ToString("X2");
                    }
					catch (Exception)
					{

					}
                    

                });
			}
		}

	}
}
